<template>
  <div>
    <Title title="实时用电"></Title>
    <div class="right_center">
      <div>
        <img src="../../assets/images/用电量.png" alt="" />
        <div>
          <p>72760</p>
          <p>总用电量（kw）</p>
        </div>
      </div>
      <div>
        <img src="../../assets/images/用电量.png" alt="" />
        <div>
          <p>75670</p>
          <p>总用水量（kw/h）</p>
        </div>
      </div>
    </div>
    <div class="top_tu">
      <MyEearts :option="option"></MyEearts>
    </div>
  </div>
</template>
<script setup>
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'
import Title from '../commont/Title.vue'
import { getdian } from '../../request/index'
import MyEearts from '../../components/commont/MyEearts.vue'
let option = ref({
  color: ['#80FFA5', '#00DDFF', '#37A2FF', '#FF0087', '#FFBF00'],
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      label: {
        backgroundColor: '#6a7985'
      }
    }
  },
  legend: {
    show: false,
    icon: 'circle',
    textStyle: {
      color: '#fff'
    },
    itemStyle: {
      color: 'rgb(255, 0, 135)'
    },
    data: ['2']
  },
  grid: {
    left: '0%',
    right: '4%',
    bottom: '3%',
    height: '80px', //强制Swiper的高度(px)，当你的Swiper在隐藏状态下初始化时且切换方向为垂直才用得上。这个参数会使自适应失效。
    containLabel: true
  },
  xAxis: [
    {
      type: 'category',
      boundaryGap: false,
      data: [
        '0.00',
        '2.00',
        '4.00',
        '6.00',
        '8.00',
        '10.00',
        '12.00',
        '14.00',
        '16.00',
        '18.00',
        '20.00',
        '22.00',
        '24.00'
      ]
    }
  ],
  yAxis: [
    {
      type: 'value'
    }
  ],
  series: [
    {
      name: '2',
      type: 'line',
      stack: 'Total',
      smooth: true,
      lineStyle: {
        width: 3,
        color: 'rgb(255, 0, 135)'
      },
      showSymbol: false,
      areaStyle: {
        opacity: 0.8,
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          {
            offset: 0,
            color: '#FF0040'
          },
          {
            offset: 1,
            color: '#00006A'
          }
        ])
      },
      emphasis: {
        focus: 'series'
      },
      data: [220, 402, 231, 134, 190, 230, 120]
    }
  ]
})
onMounted(() => {
  getdian().then((res) => {
    // console.log(res)
    let name = res.data.data.map((item, index) => {
      return item.category
    })
    let names = [...new Set(name)]
    option.value.legend.data = names
    option.value.series[0].name = names.toString()
    option.value.series[0].data = res.data.data.map((item) => item.value)
  })
})
</script>


<style  scoped lang='scss'>
.top_item {
  font-size: 16px;
  margin-top: 10px;
  width: 100%;
  height: 330px;
  background: #0c1d5f;
}
.right_center {
  color: #fff;
  height: 60px;
  margin-top: 15px;
  display: flex;
}
.right_center > div:nth-child(1) {
  margin-right: 20px;
}
.right_center > div {
  width: 50%;
  height: 100%;
  background: #0c1d5f;
  border: 1px solid blue;
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.top_tu {
  width: 100%;
  height: 260px;
  margin-top: 20px;
  background: #0c1d5f;
  border: 1px solid blue;
}
</style>
